package com.easy.controller;

import com.easy.bean.AdoptBean;
import com.easy.service.AdoptBeanService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin//允许请求跨域
@RequestMapping("adopt")
public class AdoptController {
    @Autowired
    AdoptBeanService adoptBeanService;

    @PostMapping
    public Result add(@RequestBody AdoptBean adoptBean){
        Object obj=adoptBeanService.add(adoptBean);
        return Result.success(obj);
    }

    @DeleteMapping("{id}")
    public Result del(@PathVariable("id") Integer id){
        int obj=adoptBeanService.del(id);
        return Result.success("删除成功"+obj);
    }

    @PutMapping
    public Result edit(@RequestBody AdoptBean adoptBean){
        Object obj=adoptBeanService.edit(adoptBean);
        return Result.success("编辑信息保存成功"+obj);
    }

    @GetMapping("all")
    public Result all(@RequestBody AdoptBean adoptBean){
        Object obj=adoptBeanService.all(adoptBean);
        return Result.success(obj);
    }
    @GetMapping("{id}")
    public Result one(@PathVariable("id") Integer id){
        Object obj=adoptBeanService.one(id);
        return Result.success(obj);
    }

    @GetMapping("page")
    public Result page(Page page,AdoptBean adoptBean){
        //查询一共有多少数据
        //查询当前页要显示的数据
        //将以上数据封装到page对象中
        adoptBeanService.page(page,adoptBean);
        //返回page对象
        return Result.success(page);
    }
}




















